package com.jkoss.wine.investment.service.impl;

import com.jkoss.common.util.CommonUtil;
import com.jkoss.wine.investment.entity.Investment;
import com.jkoss.wine.investment.mapper.InvestmentMapper;
import com.jkoss.wine.investment.service.IInvestmentService;
import com.jkoss.wine.investment.vo.InvestmentVo;
import com.jkoss.wine.system.entity.MerchantEmployees;
import com.jkoss.wine.system.entity.MessageNotification;
import com.jkoss.wine.system.entity.Role;
import com.jkoss.wine.system.mapper.MessageNotificationMapper;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 招商信息 服务实现类
 * 
 * @Author Ning
 * @Version 1.0, 2018-10-25
 * @See
 * @Since com.jkoss.wine.investment.service.impl
 * @Description: TODO
 */
@Service
public class InvestmentServiceImpl extends ServiceImpl<InvestmentMapper, Investment> implements IInvestmentService {
	@Autowired
	private MessageNotificationMapper messageNotificationMapper;

	@Override
	public Page selectVoPage(Page page, Wrapper wrapper) {
		SqlHelper.fillWrapper(page, wrapper);
		page.setRecords(baseMapper.selectVoPage(page, wrapper));
		return page;
	}

	@Override
	public InvestmentVo selectVoByid(Wrapper wrapper) {
		return this.baseMapper.selectVoByid(wrapper);
	}

	@Override
	public boolean insert(Investment entity) {
		MessageNotification messageNotification = new MessageNotification();
		// 员工id
		messageNotification.setMeid(entity.getMaid());
		// 标题
		messageNotification.setTitle("周报未读提醒");
		// 内容
		// messageNotification.setContent(entity.get + ",未读提醒");
		// 是否已读：0-未读、1-已读
		messageNotification.setIsread(0);
		// 添加时间
		messageNotification.setAddTime(CommonUtil.getDate());
		// 是否删除
		messageNotification.setDel(0);
		// 类型：1-通知公告未读提醒、2-周报、3-月报未读及未提交提醒、4-新客户资源分配提醒、5-资源客户未沟通提醒
		messageNotification.setType(4);
		// 操作人
		messageNotification.setOperator(entity.getOperator());
		messageNotificationMapper.insert(messageNotification);
		return super.insert(entity);
	}

	@Override
	public boolean updateMaid(String ids, String maid) {
		Investment investment = new Investment();
		investment.setMaid(maid);
		String[] id = ids.split(",");
		Wrapper wrapper = Condition.create().in("id", id);
		baseMapper.update(investment, wrapper);
		return true;
	}

}
